package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.GoodsBean;
import com.project.service.IGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("goods")
@Api(tags = "库存商品控制层")
public class GoodsController {
    @Autowired
    private IGoodsService goodsService;
    /**
     * 分页动态查询库存商品
     * 输入：页码，商品名称，起始数量，结束数量，是否定价，类别
     * 处理：分页动态查询库存
     * 输出：分页对象
     * 库存商品信息：商品编号、商品名、类别、品牌、库存数量
     * @param pageNum
     * @param goodsName
     * @param minNum
     * @param maxNum
     * @param isSuggestPrice
     * @param type
     * @return
     */
    @ApiOperation(value = "分页动态查询库存商品")
    @GetMapping("cutFindByItem")
    public IPage<GoodsBean> cutFindByItem(Integer pageNum,String goodsName,
                                          Integer minNum,Integer maxNum,String isSuggestPrice,String type){
        return goodsService.cutFindByItem(pageNum, goodsName, minNum, maxNum, isSuggestPrice, type);
    }

    /**
     * 查看库存商品信息
     * 输入：商品编号
     * 处理：根据商品编号查询库存商品信息
     * 输出：库存商品对象
     * 库存商品（商品编号，商品名称，商品图片，类别，品牌，库存量，最新采购价，建议销售价）
     * @param goodsId
     * @return
     */
    @ApiOperation(value = "查看库存商品信息")
    @GetMapping("findById")
    public GoodsBean findById(Integer goodsId){
        return goodsService.findById(goodsId);
    }

    /**
     * 修改建议销售价
     * 输入：商品编号，建议销售价
     * 处理：根据商品编号，修改新建议销售价
     * 处理：ok
     * @param goodsId
     * @param newSuggestPrice
     * @return
     */
    @ApiOperation(value = "修改建议销售价")
    @PutMapping("updateSuggestPrice")
    public String updateSuggestPrice(Integer goodsId,Integer newSuggestPrice){
        goodsService.updateSuggestPrice(goodsId, newSuggestPrice);
        return "ok";
    }
}
